package com.example.demo.mapper;

import com.example.demo.entity.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("select*from user")
    List<User> findAll();

    @Insert("INSERT INTO `user`( `username`, `password`) VALUES (#{username}, #{password});")
    @Transactional
    int insert(User user);


    @Update("update user set password=#{password} where username=#{username}")
    int update(User user);

    @Select("select * from user where username=#{username} and password=#{password}")
    User login(@Param("username")String username, @Param("password")String password);
}
